package com.jymj.service.impl;

import com.jymj.dao.IllegalDao;
import com.jymj.entity.CjEntity;
import com.jymj.entity.SysUserEntity;
import com.jymj.entity.YlEntity;
import com.jymj.entity.landmanage.IllegalEntity;
import com.jymj.entity.landmanage.IllegalFileEntity;
import com.jymj.entity.landmanage.IllegalHistoryCount;
import com.jymj.entity.landmanage.IllegaltjEntity;
import com.jymj.entity.zjd.ZjdCountEntity;
import com.jymj.service.CJService;
import com.jymj.service.IllegalService;
import com.jymj.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by dl on 2019/9/25.
 */
@Service
@Transactional
public class IllegalServiceImpl implements IllegalService {

    @Autowired
    private IllegalDao illegalDao;
    @Autowired
    private CJService cjService;

    @Override
    public int save(IllegalEntity illegalEntity) {
        illegalEntity.setStatus(0);
        illegalEntity.setEntime(new Date());
        int i = illegalDao.save(illegalEntity);
        if (illegalEntity.getIds() != null && illegalEntity.getIds().length > 0){
            illegalDao.updateFile(illegalEntity);
        }
        return i;
    }

    @Override
    public List<IllegalEntity> queryList(Map<String, Object> params) {
        /*SysUserEntity sysUserEntity = ShiroUtils.getUserEntity();
        params.put("sysUser",sysUserEntity);*/
        return illegalDao.queryList(params);
    }
    @Override
    public List<IllegaltjEntity> queryTj(String xzqmc, Integer type) {
        Map map  = new HashMap();
        SysUserEntity sysUserEntity = ShiroUtils.getUserEntity();
        map.put("sysUser",sysUserEntity);
        map.put("xzqmc",xzqmc);
        map.put("type",type);
        return illegalDao.queryTj(map);
    }

    @Override
    public YlEntity queryByPoint(String point) {
        Map map  = new HashMap();
        //查询权限内的村
        //查询权限内的村
        SysUserEntity sysUserEntity = ShiroUtils.getUserEntity();
        map.put("sysUser",sysUserEntity);
        map.put("points",point);
        return illegalDao.queryByPoint(map);
    }

    @Override
    public IllegalHistoryCount getIllegalHistoryCount(String xzqmc, String points, Integer type, String code) {
        if (type == null || type == 0){
            return null;
        }
        Map map  = new HashMap();
        //查询权限内的村
        //查询权限内的村
        SysUserEntity sysUserEntity = ShiroUtils.getUserEntity();
        map.put("sysUser",sysUserEntity);
        map.put("points",points);
        map.put("xzqmc",xzqmc);
        map.put("type",type);
        map.put("code",code);
        if (type == 1){
            return illegalDao.getIllegalHistoryCount(map);
        }else {
            return illegalDao.getTdHistoryCount(map);
        }

    }

    @Override
    public CjEntity queryCjByPoint(String point) {
        Map map  = new HashMap();
        SysUserEntity sysUserEntity = ShiroUtils.getUserEntity();
        //map.put("sysUser",sysUserEntity);
        map.put("point",point);
        CjEntity cjEntity = cjService.queryCjByPoint(map);
        return cjEntity;
    }

    @Override
    public List<IllegalEntity> queryByLocation(String point) {
        return illegalDao.queryByLocation(point);
    }

    @Override
    public ZjdCountEntity queryIllCount(String point, Integer type, String code) {
        return illegalDao.queryIllCount(point,type,code);
    }

    @Override
    public List<IllegalFileEntity> queryFiles(Integer id) {
        return illegalDao.queryFiles(id);
    }

    @Override
    public int updateStatus(IllegalEntity illegalEntity) {
        if (illegalEntity.getIds() != null && illegalEntity.getIds().length > 0){
            illegalDao.updateFile(illegalEntity);
        }
        return illegalDao.updateStatus(illegalEntity);
    }

    @Override
    public int delete(Integer id) {
        return illegalDao.delete(id);
    }

    @Override
    public void saveFile(IllegalFileEntity illegalFileEntity) {
        illegalDao.saveFile(illegalFileEntity);
    }

    @Override
    public int queryTotal(Map<String, Object> params) {
       /* SysUserEntity sysUserEntity = ShiroUtils.getUserEntity();
        params.put("sysUser",sysUserEntity);*/
        return illegalDao.queryTotal(params);
    }
}
